package com.mer.controller;

import com.mer.entity.Role;
import com.mer.entity.RolePermission;
import com.mer.service.RoleService;
import com.mer.vo.CommonResult;
import com.mer.vo.RolePermissionVo;
import com.mer.vo.RoleVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @program: IIPhase-project
 * @description: 角色权限功能块
 * @author: 冯彦凯
 * @create: 2021-10-19 09:48
 **/

@RestController
@RequestMapping("role")
@CrossOrigin
public class RoleController {
    @Resource
    private RoleService roleService;
    @ApiOperation("查询所有的角色信息")
    @PostMapping("getAllRoleUser/{page}/{limit}")
    public CommonResult getAllRoleUser(
            @PathVariable Integer page,
            @PathVariable Integer limit,
            @RequestBody Role roleVo
            ){
        return roleService.getAllRoleUser(page,limit,roleVo);
    }
    @ApiOperation("修改ID对应角色的状态")
    @PostMapping("updateRoleStatusById/{id}/{deleted}")
    public CommonResult updateRoleStatusById(
            @PathVariable String id,
            @PathVariable Integer deleted
    ){
        return roleService.updateRoleStatusById(id, deleted);
    }

    @ApiOperation("添加或修改角色信息")
    @PostMapping("addOrUpdateInfo")
    public CommonResult addOrUpdateInfo(@RequestBody Role role){
        System.out.println(role);
        return roleService.addOrUpdateInfo(role);
    }

    @ApiOperation("删除Id对应的角色信息")
    @DeleteMapping("deleteInfoById/{roleid}")
    public CommonResult deleteInfoById(
            @PathVariable String roleid){
        System.out.println(roleid);
        return roleService.deleteInfoById(roleid);
    }

    @ApiOperation("显示角色Id对应的权限")
    @GetMapping("findPermissionByRoleId/{roleId}")
    public CommonResult findPermissionByRoleId(
            @PathVariable String roleId
    ){
        return roleService.findPermissionByRoleId(roleId);
    }

    @ApiOperation("修改角色的权限")
    @PostMapping("confirmRolePower")
    public CommonResult confirmRolePower(
            @RequestBody RolePermissionVo rolePermissionVo
            ){
        return roleService.confirmRolePower(rolePermissionVo);
    }
}
